import { computed, ref } from 'vue'
import { useI18n } from 'vue-i18n'

export function useAppI18n() {
  const { locale, t } = useI18n()
  
  // 当前语言
  const currentLanguage = computed(() => locale.value)
  
  // 语言选项
  const languageOptions = {
    zh: '中文',
    ug: 'ئۇيغۇرچە'
  }
  
  // 切换语言
  const switchLanguage = (lang: 'zh' | 'ug') => {
    locale.value = lang
    // 保存到本地存储
    uni.setStorageSync('locale', lang)
    
    // 显示切换提示
    uni.showToast({
      title: lang === 'zh' ? t('message.switchToZh') : t('message.switchToUg'),
      icon: 'none'
    })
  }
  
  // 切换到下一个语言
  const toggleLanguage = () => {
    const nextLang = locale.value === 'zh' ? 'ug' : 'zh'
    switchLanguage(nextLang)
  }
  
  // 获取当前语言显示文本
  const getCurrentLanguageText = computed(() => {
    return languageOptions[locale.value as keyof typeof languageOptions]
  })
  
  return {
    t,
    locale,
    currentLanguage,
    languageOptions,
    switchLanguage,
    toggleLanguage,
    getCurrentLanguageText
  }
}